<?php

namespace App\Jobs;

use Carbon\Carbon;
use Illuminate\Bus\Queueable;
use Illuminate\Queue\SerializesModels;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Support\Facades\DB;

class SynDevice implements ShouldQueue
{
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    /**
     * Create a new job instance.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Execute the job.
     *
     * @return void
     */
    public function handle()
    {
        //同步到数据库
        $redis = app('redis');
//        $keys = $redis->keys("msg:device:*");
//        $device = [];
//        if($keys){
            file_put_contents('DesR.txt' , var_export(time(), true),FILE_APPEND);
//            $reference_at =Carbon::now()->subDays(2)->toDateTimeString();
//            foreach($keys as $devices){
//                $data =$redis->hgetall($devices);
//                $device[] = $data;
//                $device = array_chunk($data,2000);
//        foreach
//                if(isset($device['updated_at'])){
//                    if($device['updated_at'] >= $reference_at){
//                        DB::table("device")->where("sn",$device['sn'])->update(["status"=>$device['status'],"num"=>$device['num'],"Record_at"=>$device['Record_at'],"updated_at"=>$device['updated_at']]);
//                    }
//                }
//            }
//        }

//        $keys =



    }
}
